// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ADVERSE_REACTION_GROUP_ADT_A60 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 IAM",11)]
  	    [HL7Field(HL7Version.v27, 11, HL7Repeat.False, HL7Required.True,"IAM")]
	    public IAM IAM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 NTE",12)]
  	    [HL7Field(HL7Version.v27, 12, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("13 IAR",13)]
  	    [HL7Field(HL7Version.v27, 13, HL7Repeat.True, HL7Required.False,"IAR")]
	    public IAR[] IAR {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			IAM = PopSegmentParseAndCheckRequired<IAM>(availableData, options, "IAM");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			IAR = PopSegmentParseAndCheckRequiredArray<IAR>(availableData, options, "IAR");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isIAM = availableData.StartsWith("IAM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("IAM", options.Version) || isIAM) {
				return isIAM;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			bool isIAR = availableData.StartsWith("IAR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("IAR", options.Version) || isIAR) {
				return isIAR;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ADVERSE_REACTION_GROUP";
			}
        }

        static ADVERSE_REACTION_GROUP_ADT_A60() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ADVERSE_REACTION_GROUP_ADT_A60));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (IAM != null) {
			string segmentValue = IAM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (IAR != null && IAR.Length > 0) {
			for (int i = 0; i < IAR.Length; i++) {
				string segmentValue = IAR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

